package com.silence.annotation;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class DemoMainTest {
    @Test
    public void parseClass(){
        Class<Demo> demoClass = Demo.class;
        // 解析类上的注解
        System.out.println(demoClass.isAnnotationPresent(MyTest4.class));
        MyTest4 demoAnnotation = demoClass.getDeclaredAnnotation(MyTest4.class);
        System.out.println(demoAnnotation.value());
        System.out.println(demoAnnotation.aaa());
        System.out.println(Arrays.toString(demoAnnotation.bbb()));
    }

    @Test
    public void parseMethod() throws NoSuchMethodException {
        Class<Demo> demoClass = Demo.class;
        Method demotest1 = demoClass.getDeclaredMethod("test1");
        // 解析类上的注解
        System.out.println(demotest1.isAnnotationPresent(MyTest4.class));
        MyTest4 test1Annotation = demotest1.getDeclaredAnnotation(MyTest4.class);
        System.out.println(test1Annotation.value());
        System.out.println(test1Annotation.aaa());
        System.out.println(Arrays.toString(test1Annotation.bbb()));
    }

    //
    @MyTestJunit
    public void test1(){
        System.out.println("------test1------");
    }
    public void test2(){
        System.out.println("------test2------");
    }
    @MyTestJunit
    public void test3(){
        System.out.println("------test3------");
    }
    public void test4(){
        System.out.println("------test4------");
    }
    @MyTestJunit
    public void test5(){
        System.out.println("------test5------");
    }

    public static void main(String[] args) throws Exception {
        DemoMainTest demoMainTest = new DemoMainTest();
        Class jClass = DemoMainTest.class;
        Method[] jMethods = jClass.getDeclaredMethods();
        for (Method jMethod : jMethods) {
            if(jMethod.isAnnotationPresent(MyTestJunit.class)){
                jMethod.invoke(demoMainTest);
            }
        }
    }
}
